<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <div id="app">
    <input v-model="username" type="text" />
    <child1 name="李四" age="20" @pay-money="moneyHandler">
    </child1>
    <!-- <child1 :name="username"></child1> -->

    <h2>我的乖儿子又管我要钱，死孩子这次要{{money}}😭</h2>

  </div>

  <template id="child1">
    <div>
      <h1>你好鸭，我是{{name}}，我今年{{age}}岁了</h1>
      <h2>{{count}}</h2>
      <button @click="count++">+++</button>

      <button @click="callToMyFather">给爸爸打电话</button>
    </div>
  </template>
  <!-- 引入vue文件 -->
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <script>
    const app = new Vue({
      el: '#app',
      components: {
        child1: {
          template: '#child1',
          props: ['name', 'age'],
          data() {
            return {
              count: 0
            }
          },
          methods: {
            callToMyFather() {
              // 向爸爸要钱
              this.$emit('pay-money', this.count)
            }
          }
        },
      },
      data: {
        username: '',
        money: 0
      },
      methods: {
        moneyHandler(num) {
          this.money = num
        }
      }
    })

  </script>
</body>

</html>